package com.xkh.demo1.controller;

import com.xkh.demo1.entity.Score;
import com.xkh.demo1.entity.User;
import com.xkh.demo1.model.UserScoreVo;
import com.xkh.demo1.service.IScoreService;
import com.xkh.demo1.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;
import java.util.List;

/**
 * @author xkh
 * @since 2021/7/20 0020
 * http://localhost:8601/insert?id=1&name=lhd&age=12
 * http://localhost:8601/insert?id=2&name=lhd&age=13
 * http://localhost:8601/insert?id=3&name=lhd&age=14
 * http://localhost:8601/insert?id=4&name=lhd&age=15
 *
 * http://localhost:8601/select
 */
@RestController
@Api(tags = "分库分表模块")
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private IScoreService scoreService;

    @GetMapping("/select")
    @ApiOperation("查询")
    public List<User> select() {
        return userService.list();
    }

    @GetMapping("/insert")
    @ApiOperation("插入")
    public Boolean insert(User user){
        return user.insert();
    }


    @GetMapping("/selectScore")
    @ApiOperation("查询分数")
    public List<Score> selectScore(){
        return scoreService.list();
    }

    @GetMapping("/insertScore")
    @ApiOperation("插入分数")
    public Boolean insertScore(Score score){
        return score.insert();
    }

    @GetMapping("/selectScoreUser")
    @ApiOperation("多张表查询")
    public  List<UserScoreVo> selectScoreUser(Integer userId){
        return scoreService.selectScoreUser(userId);
    }
}
